from django.shortcuts import render
#coding:utf-8
from django.http import HttpResponse
from django.shortcuts import render

import urllib
import http.client


def index(request):
    return HttpResponse(u"欢迎光临 自强学堂!")

def add(request):
    a = request.GET['a']
    b = request.GET['b']
    c = int(a)+int(b)
    getAccountDetail()
    return HttpResponse(str(c))

def add2(request,a,b):
    c = int(a) + int(b)
    return HttpResponse(str(c))

def home(request):

    return render(request, 'home.html')

def getAccountDetail():

    httpClient = None

    try:
        headers = {'User-Agent':'ProfileManager-1.0',
                   'X-Server-Protocol-Version':'',
                   'X-ADM-Auth-Session':'',
                   "Content-type": 'application/json;charset=UTF8',
                   "Accept": "text/plain",
                   'consumer_key':'',
                   'consumer_secret':'',
                   'access_token':''}
        httpClient = httpClient.HTTPConnection('https://mdmenrollment.apple.com', timeout=30)
        httpClient.request('GET', '/account', headers)

        #response是HTTPResponse对象
        response = httpClient.getresponse()
        print(response.status)
        print(response.reason)
        print(response.read())
    except Exception:
        print(Exception.__doc__)
    finally:
        if httpClient:
            httpClient.close()



def getFetchDevices():

    httpClient = None

    try:
        headers = {'User-Agent':'ProfileManager-1.0',
                   'X-Server-Protocol-Version':'',
                   'X-ADM-Auth-Session':'',
                   "Content-type": 'application/json;charset=UTF8',
                   "Accept": "text/plain",
                   'consumer_key':'',
                   'consumer_secret':'',
                   'access_token':''}
        httpClient = httpClient.HTTPConnection('https://mdmenrollment.apple.com', timeout=30)
        httpClient.request('GET', '/server/devices', headers)

        #response是HTTPResponse对象
        response = httpClient.getresponse()
        print(response.status)
        print(response.reason)
        print(response.read())
    except Exception:
        print('exception----' + Exception.__doc__)
    finally:
        if httpClient:
            httpClient.close()


def syncDevices():

    httpClient = None

    try:
        headers = {'User-Agent':'ProfileManager-1.0',
                   'X-Server-Protocol-Version':'',
                   'X-ADM-Auth-Session':'',
                   "Content-type": 'application/json;charset=UTF8',
                   "Accept": "text/plain",
                   'consumer_key':'',
                   'consumer_secret':'',
                   'access_token':''}
        httpClient = httpClient.HTTPConnection('https://mdmenrollment.apple.com', timeout=30)
        httpClient.request('GET', '/server/devices', headers)

        #response是HTTPResponse对象
        response = httpClient.getresponse()
        print(response.status)
        print(response.reason)
        print(response.read())
    except Exception:
        print('exception----' + Exception.__doc__)
    finally:
        if httpClient:
            httpClient.close()

def deviceDetails():

    httpClient = None

    try:
        headers = {'User-Agent':'ProfileManager-1.0',
                   'X-Server-Protocol-Version':'',
                   'X-ADM-Auth-Session':'',
                   "Content-type": 'application/json;charset=UTF8',
                   "Accept": "text/plain",
                   'consumer_key':'',
                   'consumer_secret':'',
                   'access_token':''}
        httpClient = httpClient.HTTPConnection('https://mdmenrollment.apple.com', timeout=30)
        httpClient.request('GET', '/server/devices', headers)

        #response是HTTPResponse对象
        response = httpClient.getresponse()
        print(response.status)
        print(response.reason)
        print(response.read())
    except Exception:
        print('exception----' + Exception.__doc__)
    finally:
        if httpClient:
            httpClient.close()

def disownDevices():

    httpClient = None

    try:
        headers = {'User-Agent':'ProfileManager-1.0',
                   'X-Server-Protocol-Version':'',
                   'X-ADM-Auth-Session':'',
                   "Content-type": 'application/json;charset=UTF8',
                   "Accept": "text/plain",
                   'consumer_key':'',
                   'consumer_secret':'',
                   'access_token':''}
        httpClient = httpClient.HTTPConnection('https://mdmenrollment.apple.com', timeout=30)
        httpClient.request('GET', '/server/devices', headers)

        #response是HTTPResponse对象
        response = httpClient.getresponse()
        print(response.status)
        print(response.reason)
        print(response.read())
    except Exception:
        print('exception----' + Exception.__doc__)
    finally:
        if httpClient:
            httpClient.close()

def defineProfile():

    httpClient = None

    try:
        headers = {'User-Agent':'ProfileManager-1.0',
                   'X-Server-Protocol-Version':'',
                   'X-ADM-Auth-Session':'',
                   "Content-type": 'application/json;charset=UTF8',
                   "Accept": "text/plain",
                   'consumer_key':'',
                   'consumer_secret':'',
                   'access_token':''}
        httpClient = httpClient.HTTPConnection('https://mdmenrollment.apple.com', timeout=30)
        httpClient.request('GET', '/server/devices', headers)

        #response是HTTPResponse对象
        response = httpClient.getresponse()
        print(response.status)
        print(response.reason)
        print(response.read())
    except Exception:
        print('exception----' + Exception.__doc__)
    finally:
        if httpClient:
            httpClient.close()

def assignProfile():

    httpClient = None

    try:
        headers = {'User-Agent':'ProfileManager-1.0',
                   'X-Server-Protocol-Version':'',
                   'X-ADM-Auth-Session':'',
                   "Content-type": 'application/json;charset=UTF8',
                   "Accept": "text/plain",
                   'consumer_key':'',
                   'consumer_secret':'',
                   'access_token':''}
        httpClient = httpClient.HTTPConnection('https://mdmenrollment.apple.com', timeout=30)
        httpClient.request('GET', '/server/devices', headers)

        #response是HTTPResponse对象
        response = httpClient.getresponse()
        print(response.status)
        print(response.reason)
        print(response.read())
    except Exception:
        print('exception----' + Exception.__doc__)
    finally:
        if httpClient:
            httpClient.close()


def fetchProfile():

    httpClient = None

    try:
        headers = {'User-Agent':'ProfileManager-1.0',
                   'X-Server-Protocol-Version':'',
                   'X-ADM-Auth-Session':'',
                   "Content-type": 'application/json;charset=UTF8',
                   "Accept": "text/plain",
                   'consumer_key':'',
                   'consumer_secret':'',
                   'access_token':''}
        httpClient = httpClient.HTTPConnection('https://mdmenrollment.apple.com', timeout=30)
        httpClient.request('GET', '/server/devices', headers)

        #response是HTTPResponse对象
        response = httpClient.getresponse()
        print(response.status)
        print(response.reason)
        print(response.read())
    except Exception:
        print('exception----' + Exception.__doc__)
    finally:
        if httpClient:
            httpClient.close()

def removeProfile():

    httpClient = None

    try:
        headers = {'User-Agent':'ProfileManager-1.0',
                   'X-Server-Protocol-Version':'',
                   'X-ADM-Auth-Session':'',
                   "Content-type": 'application/json;charset=UTF8',
                   "Accept": "text/plain",
                   'consumer_key':'',
                   'consumer_secret':'',
                   'access_token':''}
        httpClient = httpClient.HTTPConnection('https://mdmenrollment.apple.com', timeout=30)
        httpClient.request('GET', '/server/devices', headers)

        #response是HTTPResponse对象
        response = httpClient.getresponse()
        print(response.status)
        print(response.reason)
        print(response.read())
    except Exception:
        print('exception----' + Exception.__doc__)
    finally:
        if httpClient:
            httpClient.close()













